﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArch.Utils;

namespace YJKArch.Aproll.DataDefine
{
	public class BaseLineNode
	{
		public XYZ Position
		{
			get
			{
				return this.m_ptPosition;
			}
		}

		public List<BaseLineSegment> SegmentList
		{
			get
			{
				return this.m_SegmentList;
			}
		}

		public void AddSegment(BaseLineSegment segment)
		{
			this.m_SegmentList.Add(segment);
		}

		public void RemoveSegment(BaseLineSegment segment)
		{
			int num = this.m_SegmentList.FindIndex((BaseLineSegment value) => value.IsEqual(segment));
			if (num >= 0 && num < this.m_SegmentList.Count)
			{
				this.m_SegmentList.RemoveAt(num);
			}
		}

		public int FindLinkSegmentWithOtherNode(XYZ ptOtherNode)
		{
			double eps = 0.01;
			List<int> list = new List<int>();
			for (int i = 0; i < this.m_SegmentList.Count; i++)
			{
				XYZ xyz = this.m_SegmentList[i].CurEndPoint(this.m_ptPosition);
				if (xyz != null && Geometry.IsEqual(ptOtherNode, xyz, eps))
				{
					list.Add(i);
				}
			}
			if (list.Count < 1)
			{
				return -1;
			}
			return list[list.Count - 1];
		}

		public BaseLineNode(BaseLineNode rhs)
		{
			this.m_ptPosition = rhs.m_ptPosition;
			this.m_SegmentList = rhs.m_SegmentList;
		}

		public BaseLineNode(XYZ ptPosition, List<BaseLineSegment> segmentList)
		{
			this.m_ptPosition = ptPosition;
			this.m_SegmentList = segmentList;
		}

		private XYZ m_ptPosition;

		private List<BaseLineSegment> m_SegmentList = new List<BaseLineSegment>();
	}
}
